package com.lifeng.patterns.templatemethod;

import java.util.Map;

/**
 * Created by lifeng on 2019/10/16.
 * 调用微信
 */
public class WechatPayReromeCall extends AbstractRemoteCall{
    @Override
    protected Object getBean(Map<String, Object> reqMap) {
        WechatpayDto wechatpayDto = new WechatpayDto();
        wechatpayDto.setMchId((String) reqMap.get("merid"));
        wechatpayDto.setMerNo((String) reqMap.get("orderno"));
        wechatpayDto.setTranAmt((Long) reqMap.get("amt"));
        wechatpayDto.setGoodsName((String) reqMap.get("body"));
        return wechatpayDto;
    }

    @Override
    public Object executeBiz(Object obj) throws Exception {
        //TODO 模拟调用远程
        WechatpayDto wechatpayDto = new WechatpayDto();
        wechatpayDto.setCode("200");
        wechatpayDto.setMsg("交易成功");
        wechatpayDto.setMerNo("11111111111");
        return wechatpayDto;
    }

    @Override
    public Map<String, Object> getRspMap(Object ret, Map<String, Object> rspMap) throws Exception {
        WechatpayDto wechatpayDto = (WechatpayDto) ret;
        rspMap.put("orderno",wechatpayDto.getMerNo());
        rspMap.put("rspcode",wechatpayDto.getCode());
        rspMap.put("rspmsg",wechatpayDto.getMsg());
        return rspMap;
    }
}
